package com.hh.service.service.impl.merchant;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hh.common.model.merchant.MerchantRoleMenu;
import com.hh.service.dao.merchant.MerchantRoleMenuDao;
import com.hh.service.service.merchant.MerchantRoleMenuService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class MerchantRoleMenuServiceImpl extends ServiceImpl<MerchantRoleMenuDao, MerchantRoleMenu> implements MerchantRoleMenuService {

    @Resource
    private MerchantRoleMenuDao dao;

    @Override
    public Boolean deleteByRid(Integer rid) {
        LambdaUpdateWrapper<MerchantRoleMenu> luw = Wrappers.lambdaUpdate();
        luw.eq(MerchantRoleMenu::getRid, rid);
        return dao.delete(luw) > 0;
    }

    @Override
    public List<Integer> getMenuListByRid(Integer rid) {
        LambdaQueryWrapper<MerchantRoleMenu> lqw = Wrappers.lambdaQuery();
        lqw.select(MerchantRoleMenu::getMenuId);
        lqw.eq(MerchantRoleMenu::getRid, rid);
        List<MerchantRoleMenu> roleMenuList = dao.selectList(lqw);
        return roleMenuList.stream().map(MerchantRoleMenu::getMenuId).collect(Collectors.toList());
    }
}
